import {request} from "@umijs/max";
import {AUDIO} from "@/services/audio/audio.typings";

export async function getAllAudios(params: AUDIO.GetAudiosParams, options?: { [key: string]: any }) {
  // 将 params 对象转换为查询字符串
  const queryString = new URLSearchParams(params as any).toString();

  return request<{
    data: AUDIO.GetAudiosResult
  }>(`/audio/searchAudio?${queryString}`, {
    method: 'GET',
    // params: {
    //   ...params
    // },
    ...(options || {}),
  });
}

export async function addOrUpdateAudio(body: AUDIO.AddOrUpdateAudioParams, options?: { [key: string]: any }) {
  return request<{
    data: API.ApiResult
  }>('/audio/addOrUpdateAudio', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

export async function uploadFile(body: FormData, options?: { [key: string]: any }) {
  return request<{
    data: API.ApiResult
  }>('/public/uploadFile', {
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data: body,
    ...(options || {}),
  });
}

export async function getAudioDetail(params: AUDIO.GetAudioDetailParams, options?: { [key: string]: any }) {
  const queryString = new URLSearchParams(params as any).toString();

  return request<{
    data: API.ApiResult
  }>(`/audio/audioDetail?${queryString}`, {
    method: 'GET',
    ...(options || {}),
  })
}

export async function getAudioCategories(params: { [key: string]: any }, options?: { [key: string]: any }) {
  const queryString = new URLSearchParams(params as any).toString();

  return request<{
    data: API.ApiResult
  }>(`/audio/searchAudioCategory?${queryString}`, {
    method: 'GET',
    ...(options || {}),
  })
}

export async function addOrUpdateAudioCategory(body: AUDIO.AddOrUpdateAudioCategoryParams, options?: { [key: string]: any }) {
  return request<{
    data: API.ApiResult
  }>('/audio/addOrUpdateAudioCategory', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}
